package backtracking;

import java.util.ArrayList;
import java.util.List;

public class LeetCode17 {
    private static String[] vals = {
            "",
            "",
            "abc",
            "def",
            "ghi",
            "jkl",
            "mno",
            "pqrs",
            "tuv",
            "wxyz"
    };
    static List<String> res = new ArrayList<>();
    static StringBuilder str = new StringBuilder(20);
    public List<String> letterCombinations(String digits) {
        if(digits.length() > 0) {
            back(digits, 0);
            return res;
        }
        return null;
    }
    public void back(String digits,int index){
        if(index == digits.length()) {
            res.add(str.toString());
            return;
        }
        String v = vals[digits.charAt(index) - '0'];
        for (int i = 0; i < v.length(); i++) {
            str.append(v.charAt(i));
            back(digits, index + 1);
            str.deleteCharAt(str.length() - 1);
        }
    }
    public static void main(String[] args) {
        String digits = "234";
        LeetCode17 leetCode17 = new LeetCode17();
        leetCode17.back(digits, 0);
        res.forEach(System.out::println);
    }
}
